package com.ultimatech.feign2.controller;

import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.shared.Application;
import com.netflix.discovery.shared.Applications;
import com.ultimatech.cloud.poc.base.model.TestData;
import com.ultimatech.feign2.service.ISchedualServiceHi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * Created by zhangleping on 2017/9/27.
 */
@RestController
public class HiController {

    @Autowired
    private ISchedualServiceHi serviceHi;

    @RequestMapping(value = "/hi",method = RequestMethod.GET)
    public String sayHi(@RequestParam String name){
        return serviceHi.sayHiFromClientOne(name);
    }

    @RequestMapping(value = "/whoami",method = RequestMethod.GET)
    public String whoami(@RequestParam(value = "name")String name){
        return serviceHi.whoami(name);
    }

    @RequestMapping(value = "/test",method = RequestMethod.GET)
    @ResponseBody
    public TestData getTestData(String name){
        return serviceHi.test(name);
    }

    @Autowired
    private EurekaClient eurekaClient;

    @RequestMapping(value = "/regInfo",method = RequestMethod.GET)
    public List<Application> getSvrs(){
        Set regions=eurekaClient.getAllKnownRegions();
        Applications applications=eurekaClient.getApplications();
        List<Application> apps=applications.getRegisteredApplications();
//        for(Application app:apps){
//            app.getInstances()
//        }
        return apps;
    }
}
